import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
//首页组件
// import HomePage from '@/components/home_page/HomePage'
const HomePage = r => require.ensure([], () => r(require('../components/home_page/HomePage')));

//商城组件
// import Mall from '@/components/mall/Mall'
const Mall = r => require.ensure([], () => r(require('../components/mall/Mall')));
// import goods from '@/components/mall/components/content_mint';
const goods = r => require.ensure([], () => r(require('../components/mall/components/content_mint')));
// import buildOrder from '@/components/mall/build_order'
const buildOrder = r => require.ensure([], () => r(require('../components/mall/build_order')));

// const WeightLossPage = r => require.ensure([], () => r(require('./routes/WeightLossPage.vue')), 'big-pages')
//点击去结算跳转到购物车
// import Cart from '@/components/mall/Cart'
const Cart = r => require.ensure([], () => r(require('../components/mall/Cart')));

//订单列表组件
// import Order from '@/components/order/OrderList'
const Order = r => require.ensure([], () => r(require('../components/order/OrderList')));
//订单详情
// import OrderDetail from '@/components/order/OrderDetail'
const OrderDetail = r => require.ensure([], () => r(require('../components/order/OrderDetail')));

//水票相关
// import WaterBillList from '@/components/water_bill/WaterBillList'
const WaterBillList = r => require.ensure([], () => r(require('../components/water_bill/WaterBillList')));

//个人中心组件
// import Personall from '@/components/personal/Personal'
const Personall = r => require.ensure([], () => r(require('../components/personal/Personal')));
//点击地址管理跳转到地址列表
// import AddressList from '@/components/personal/AddressList_new'
const AddressList = r => require.ensure([], () => r(require('../components/personal/AddressList_new')));
//地址列表点击添加地址
// import AddAddress from '@/components/personal/AddAddress_new'
const AddAddress = r => require.ensure([], () => r(require('../components/personal/AddAddress_new')));
//编辑地址
// import EditAddress from '@/components/personal/AddAddress_new'
const EditAddress = r => require.ensure([], () => r(require('../components/personal/AddAddress_new')));

//手机验证页面
// import PhoneCheck from '@/components/personal/PhoneCheck'
const PhoneCheck = r => require.ensure([], () => r(require('../components/personal/PhoneCheck')));

//水票共享页面
// import WaterBillShare from '@/components/personal/WaterBillShare'
const WaterBillShare = r => require.ensure([], () => r(require('../components/personal/WaterBillShare')));

//账号移交
// import InfoMove from '@/components/personal/InfoMove'
const InfoMove = r => require.ensure([], () => r(require('../components/personal/InfoMove')));

//店铺切换
// import ShopChange from '@/components/personal/ShopChange'
const ShopChange = r => require.ensure([], () => r(require('../components/personal/ShopChange')));

//关于我们
// import AboutUs from '@/components/personal/AboutUs'
const AboutUs = r => require.ensure([], () => r(require('../components/personal/AboutUs')));

//商城的商家介绍
// import ShopInfoAboutUs from '@/components/mall/components/ShopInfoAboutUs'
const ShopInfoAboutUs = r => require.ensure([], () => r(require('../components/mall/components/ShopInfoAboutUs')));

//技术支持
// import UsSupport from '@/components/personal/UsSupport'
const UsSupport = r => require.ensure([], () => r(require('../components/personal/UsSupport')));


//一键订水
// import BookingWater from '@/components/water_bill/BookingWater'
const BookingWater = r => require.ensure([], () => r(require('../components/water_bill/BookingWater')));

//水票支付时页面
// import WaterBillOrder from '@/components/water_bill/components/WaterBillOrder'
const WaterBillOrder = r => require.ensure([], () => r(require('../components/water_bill/components/WaterBillOrder')));

//支付成功页面
// import Success from '@/components/components/Success'
const Success = r => require.ensure([], () => r(require('../components/components/Success')));

//支付失败页面
// import Fail from '@/components/components/Fail'
const Fail = r => require.ensure([], () => r(require('../components/components/Fail')));

//我的推广页面
// import MyExtend from '@/components/personal/MyExtend'
const MyExtend = r => require.ensure([], () => r(require('../components/personal/MyExtend')));

//二维码推广页面
// import Refer from '@/components/personal/Refer'
const Refer = r => require.ensure([], () => r(require('../components/personal/Refer')));

// import ReferPerson from '@/components/personal/ReferPerson'
const ReferPerson = r => require.ensure([], () => r(require('../components/personal/ReferPerson')));

//提现
// import ApplyWithdraw from '@/components/personal/ApplyWithdraw'
const ApplyWithdraw = r => require.ensure([], () => r(require('../components/personal/ApplyWithdraw')));

//账户中心 - 水票列表
// import Ticket from '@/components/personal/Ticket'
const Ticket = r => require.ensure([], () => r(require('../components/personal/Ticket')));

//账户中心 - 水桶列表
// import Bucket from '@/components/personal/Bucket'
const Bucket = r => require.ensure([], () => r(require('../components/personal/Bucket')));

//账户中心 - 押金
// import Cash from '@/components/personal/Cash'
const Cash = r => require.ensure([], () => r(require('../components/personal/Cash')));

//扫码 - 一键订水
// import ShareTicket from '@/components/other/ShareTicket'
const ShareTicket = r => require.ensure([], () => r(require('../components/other/ShareTicket')));

//扫码 直接开店
// import Simple from '@/components/Simple'
const Simple = r => require.ensure([], () => r(require('../components/Simple')));

//选择商铺
// import ChooseShop from '@/components/ChooseShop'
const ChooseShop = r => require.ensure([], () => r(require('../components/ChooseShop')));


//测试页面
import text from '@/components/Form';



Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'HomePage',
      component: HomePage,
    },
    {
      path: '/qds/homepage',
      name: 'HomePage',
      component: HomePage //text
    },
    {
      path: '/qds/mall',
      name: 'Mall',
      component: Mall,
      redirect: '/goods',
      children: [
        {
          path: '/goods',
          component: goods
        },
        {
          path:'/shopInfo',
          component:ShopInfoAboutUs
        }
      ]
    },
    {
      path:'/qds/buildOrder',
      name:'buildOrder',
      component:buildOrder
    },
    {
      path: '/qds/personall',
      name: 'Personall',
      component: Personall
    },
    {
      path: '/qds/orderList',
      name: 'Order',
      component: Order,
      meta:{
        requireAuth: true,
      }
    },
    {
      path: '/qds/orderDetail',
      name: 'OrderDetail',
      component:OrderDetail
    },
    {
      path:'/qds/waterbilllist',
      name:'WaterBillList',
      component:WaterBillList
    },
    {
      path: '/qds/cart',
      name: 'Cart',
      component:Cart
    },
    {
      path: '/qds/addressList',
      name: 'AddressList',
      component:AddressList
    },
    {
      path: '/qds/addAddress',
      name: 'AddAddress',
      component:AddAddress
    },{
      path:'/qds/editAddress',
      name:'EditAddress',
      component:EditAddress
    },{
      path:'/qds/phoneCheck',
      name:'PhoneCheck',
      component:PhoneCheck
    },{
      path:'/qds/waterBillShare',
      name:'WaterBillShare',
      component:WaterBillShare
    },{
      path:'/qds/infoMove',
      name:'InfoMove',
      component:InfoMove
    },{
      path:'/qds/shopChange',
      name:'ShopChange',
      component:ShopChange
    },{
      path:'/qds/aboutUs',
      name:'AboutUs',
      component:AboutUs
    },{
      path:'/qds/usSupport',
      name:'UsSupport',
      component:UsSupport
    },{
      path:'/qds/bookingWater',
      name:'BookingWater',
      component:BookingWater
    },{
      path:'/qds/Success',
      name:'Success',
      component:Success
    },{
      path:'/qds/fail',
      name:'Fail',
      component:Fail
    },{
      path:'/qds/waterBillOrder',
      name:'WaterBillOrder',
      component:WaterBillOrder
    },{
      path:'/qds/myExtend',
      name:'MyExtend',
      component:MyExtend
    },{
      path:'/qds/refer',
      name:'Refer',
      component:Refer
    },{
      path:'/qds/referPerson',
      name:'ReferPerson',
      component:ReferPerson
    },{
      path:'/qds/applyWithdraw',
      name:'ApplyWithdraw',
      component:ApplyWithdraw
    },{
      path:'/qds/ticket',
      name:'Ticket',
      component:Ticket
    },{
      path:'/qds/bucket',
      name:'Bucket',
      component:Bucket
    },{
      path:'/qds/cash',
      name:'Cash',
      component:Cash
    },{
      path:'/qds/shareTicket',
      name:'ShareTicket',
      component:ShareTicket
    },{
      path:'/qds/simple',
      name:'Simple',
      component:Simple
    },{
      path:'/qds/ChooseShop',
      name:'ChooseShop',
      component:ChooseShop,

    }

  ]
})

//获取缓存
Vue.prototype.getCache = function (key) {
  if (!window.localStorage) {
    $.alert('浏览器不支持localstorage');
  } else {
    var storage = window.localStorage;
    return JSON.parse(storage.getItem(key));
  }
}

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
    console.log('需要验证登录')
    next()
  }
  else {
    console.log('不需要验证登录')
    next();
  }
})

export default router
